Imports pixolut.BizBloxBuilderCore
Imports System.Text
Imports pixolut.BizBlox
Imports System.IO
Imports System.Threading

Public Class Main
    Inherits System.Windows.Forms.Form
    Implements IMessageFilter

    Private WithEvents Project As BBXProject
    Friend WithEvents cbDtDateMapping As System.Windows.Forms.CheckBox
    Friend WithEvents btLangVb2 As System.Windows.Forms.RadioButton
    Friend WithEvents btLangCS2 As System.Windows.Forms.RadioButton
    Friend WithEvents cbBoundsChecking As System.Windows.Forms.CheckBox
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents ToolsWatchSource As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    Friend WithEvents cbAddTODataContractInfo As System.Windows.Forms.CheckBox
    Friend WithEvents mnuSaveAs As System.Windows.Forms.MenuItem
    Friend WithEvents cbAddOrderAttributeToDataContractInfo As System.Windows.Forms.CheckBox

    Private Declare Function DragAcceptFiles Lib "shell32.dll" (ByVal hwnd As IntPtr, ByVal accept As Boolean) As Long
    Private Declare Function DragQueryFile Lib "shell32.dll" (ByVal hdrop As IntPtr, ByVal ifile As Integer, ByVal fname As StringBuilder, ByVal fnsize As Integer) As Integer
    Private Declare Sub DragFinish Lib "Shell32.dll" (ByVal hdrop As IntPtr)
    Public Const WM_DROPFILES As Integer = 563

#Region " Windows Form Designer generated code "


    Public Sub New()
        MyBase.New()
        Application.EnableVisualStyles()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Me.txOut.AppendText("BizBlox Builder [Version " & Application.ProductVersion & "]" & vbCrLf)
        Dim sb As New SearchBuilder
        Me.txOut.AppendText("BizBlox API DLL [Version " & sb.GetType().Assembly.GetName().Version.ToString() & "]" & vbCrLf & vbCrLf)
        Project = New BBXProject
        Me.SetTitle()
        Dim args As String() = Environment.GetCommandLineArgs()
        If args.Length > 1 Then If File.Exists(args(1)) Then Me.DoLoad(args(1))
        Application.AddMessageFilter(Me)
        DragAcceptFiles(Me.Handle, True)
        Dim c As New Config
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents FBOutputPath As System.Windows.Forms.FolderBrowserDialog
    Friend WithEvents FOSourceFile As System.Windows.Forms.OpenFileDialog
    Friend WithEvents pgProgress As System.Windows.Forms.ProgressBar
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
    Friend WithEvents FOBBX As System.Windows.Forms.OpenFileDialog
    Friend WithEvents FSBBX As System.Windows.Forms.SaveFileDialog
    Friend WithEvents MenuItem12 As System.Windows.Forms.MenuItem
    Friend WithEvents FOSourceScript As System.Windows.Forms.OpenFileDialog
    Friend WithEvents txOut As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents FileProjectFileOpen As System.Windows.Forms.MenuItem
    Friend WithEvents mnuSave As System.Windows.Forms.MenuItem
    Friend WithEvents FileSQLFileOpen As System.Windows.Forms.MenuItem
    Friend WithEvents FileScriptFileOpen As System.Windows.Forms.MenuItem
    Friend WithEvents FileOutputPath As System.Windows.Forms.MenuItem
    Friend WithEvents FilePerformImport As System.Windows.Forms.MenuItem
    Friend WithEvents FileExit As System.Windows.Forms.MenuItem
    Friend WithEvents HelpAbout As System.Windows.Forms.MenuItem
    Friend WithEvents HelpHelpOutput As System.Windows.Forms.MenuItem
    Friend WithEvents btStep1A As System.Windows.Forms.Button
    Friend WithEvents btStep2 As System.Windows.Forms.Button
    Friend WithEvents btStep3 As System.Windows.Forms.Button
    Friend WithEvents cbDataObjects As System.Windows.Forms.CheckBox
    Friend WithEvents btStep1B As System.Windows.Forms.Button
    Friend WithEvents cbDOCollections As System.Windows.Forms.CheckBox
    Friend WithEvents cbTransferObjects As System.Windows.Forms.CheckBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents ToolsProjectInfo As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem10 As System.Windows.Forms.MenuItem
    Friend WithEvents btLangCS As System.Windows.Forms.RadioButton
    Friend WithEvents btLangVB As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Main))
        Me.FBOutputPath = New System.Windows.Forms.FolderBrowserDialog
        Me.FOSourceFile = New System.Windows.Forms.OpenFileDialog
        Me.pgProgress = New System.Windows.Forms.ProgressBar
        Me.MainMenu1 = New System.Windows.Forms.MainMenu(Me.components)
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.FileProjectFileOpen = New System.Windows.Forms.MenuItem
        Me.mnuSave = New System.Windows.Forms.MenuItem
        Me.mnuSaveAs = New System.Windows.Forms.MenuItem
        Me.MenuItem4 = New System.Windows.Forms.MenuItem
        Me.FileExit = New System.Windows.Forms.MenuItem
        Me.MenuItem10 = New System.Windows.Forms.MenuItem
        Me.FileSQLFileOpen = New System.Windows.Forms.MenuItem
        Me.FileScriptFileOpen = New System.Windows.Forms.MenuItem
        Me.MenuItem12 = New System.Windows.Forms.MenuItem
        Me.FileOutputPath = New System.Windows.Forms.MenuItem
        Me.MenuItem8 = New System.Windows.Forms.MenuItem
        Me.FilePerformImport = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.ToolsProjectInfo = New System.Windows.Forms.MenuItem
        Me.ToolsWatchSource = New System.Windows.Forms.MenuItem
        Me.MenuItem6 = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.HelpAbout = New System.Windows.Forms.MenuItem
        Me.MenuItem5 = New System.Windows.Forms.MenuItem
        Me.HelpHelpOutput = New System.Windows.Forms.MenuItem
        Me.FOBBX = New System.Windows.Forms.OpenFileDialog
        Me.FSBBX = New System.Windows.Forms.SaveFileDialog
        Me.FOSourceScript = New System.Windows.Forms.OpenFileDialog
        Me.txOut = New System.Windows.Forms.TextBox
        Me.btStep1A = New System.Windows.Forms.Button
        Me.btStep2 = New System.Windows.Forms.Button
        Me.btStep3 = New System.Windows.Forms.Button
        Me.cbDataObjects = New System.Windows.Forms.CheckBox
        Me.btStep1B = New System.Windows.Forms.Button
        Me.cbDOCollections = New System.Windows.Forms.CheckBox
        Me.cbTransferObjects = New System.Windows.Forms.CheckBox
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.btLangVB = New System.Windows.Forms.RadioButton
        Me.btLangCS = New System.Windows.Forms.RadioButton
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.btLangVb2 = New System.Windows.Forms.RadioButton
        Me.btLangCS2 = New System.Windows.Forms.RadioButton
        Me.cbDtDateMapping = New System.Windows.Forms.CheckBox
        Me.cbBoundsChecking = New System.Windows.Forms.CheckBox
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.cbAddTODataContractInfo = New System.Windows.Forms.CheckBox
        Me.cbAddOrderAttributeToDataContractInfo = New System.Windows.Forms.CheckBox
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.SuspendLayout()
        '
        'FBOutputPath
        '
        Me.FBOutputPath.Description = "Select the output folder for the classes to be rendered"
        '
        'FOSourceFile
        '
        Me.FOSourceFile.DefaultExt = "sql"
        Me.FOSourceFile.Filter = "SQL Files | *.sql"
        Me.FOSourceFile.RestoreDirectory = True
        Me.FOSourceFile.Title = "Select the SQL Script to import"
        '
        'pgProgress
        '
        Me.pgProgress.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.pgProgress.Location = New System.Drawing.Point(0, 486)
        Me.pgProgress.Name = "pgProgress"
        Me.pgProgress.Size = New System.Drawing.Size(528, 16)
        Me.pgProgress.Style = System.Windows.Forms.ProgressBarStyle.Continuous
        Me.pgProgress.TabIndex = 2
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem10, Me.MenuItem2, Me.MenuItem3})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.FileProjectFileOpen, Me.mnuSave, Me.mnuSaveAs, Me.MenuItem4, Me.FileExit})
        Me.MenuItem1.Text = "File"
        '
        'FileProjectFileOpen
        '
        Me.FileProjectFileOpen.Index = 0
        Me.FileProjectFileOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO
        Me.FileProjectFileOpen.Text = "Open BizBlox Project"
        '
        'mnuSave
        '
        Me.mnuSave.Index = 1
        Me.mnuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS
        Me.mnuSave.Text = "Save BizBlox Project"
        '
        'mnuSaveAs
        '
        Me.mnuSaveAs.Index = 2
        Me.mnuSaveAs.Text = "Save BizBlox Project As"
        '
        'MenuItem4
        '
        Me.MenuItem4.Index = 3
        Me.MenuItem4.Text = "-"
        '
        'FileExit
        '
        Me.FileExit.Index = 4
        Me.FileExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX
        Me.FileExit.Text = "Exit"
        '
        'MenuItem10
        '
        Me.MenuItem10.Index = 1
        Me.MenuItem10.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.FileSQLFileOpen, Me.FileScriptFileOpen, Me.MenuItem12, Me.FileOutputPath, Me.MenuItem8, Me.FilePerformImport})
        Me.MenuItem10.Text = "Import"
        '
        'FileSQLFileOpen
        '
        Me.FileSQLFileOpen.Index = 0
        Me.FileSQLFileOpen.Text = "Select SQL File"
        '
        'FileScriptFileOpen
        '
        Me.FileScriptFileOpen.Index = 1
        Me.FileScriptFileOpen.Text = "Select Object Script File"
        '
        'MenuItem12
        '
        Me.MenuItem12.Index = 2
        Me.MenuItem12.Text = "-"
        '
        'FileOutputPath
        '
        Me.FileOutputPath.Index = 3
        Me.FileOutputPath.Text = "Select Output Path"
        '
        'MenuItem8
        '
        Me.MenuItem8.Index = 4
        Me.MenuItem8.Text = "-"
        '
        'FilePerformImport
        '
        Me.FilePerformImport.Index = 5
        Me.FilePerformImport.Shortcut = System.Windows.Forms.Shortcut.CtrlI
        Me.FilePerformImport.Text = "Perform Import"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 2
        Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.ToolsProjectInfo, Me.ToolsWatchSource, Me.MenuItem6})
        Me.MenuItem2.Text = "Tools"
        '
        'ToolsProjectInfo
        '
        Me.ToolsProjectInfo.Index = 0
        Me.ToolsProjectInfo.Shortcut = System.Windows.Forms.Shortcut.CtrlD
        Me.ToolsProjectInfo.Text = "Show Project Info"
        '
        'ToolsWatchSource
        '
        Me.ToolsWatchSource.Index = 1
        Me.ToolsWatchSource.Text = "Watch Source File"
        '
        'MenuItem6
        '
        Me.MenuItem6.Index = 2
        Me.MenuItem6.Text = "Create Encrypted Connection String"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 3
        Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.HelpAbout, Me.MenuItem5, Me.HelpHelpOutput})
        Me.MenuItem3.Text = "Help"
        '
        'HelpAbout
        '
        Me.HelpAbout.Index = 0
        Me.HelpAbout.Text = "About"
        '
        'MenuItem5
        '
        Me.MenuItem5.Index = 1
        Me.MenuItem5.Text = "-"
        '
        'HelpHelpOutput
        '
        Me.HelpHelpOutput.Index = 2
        Me.HelpHelpOutput.Text = "Help"
        '
        'FOBBX
        '
        Me.FOBBX.DefaultExt = "BBX"
        Me.FOBBX.Filter = "BizBlox Project | *.BBX"
        Me.FOBBX.RestoreDirectory = True
        Me.FOBBX.Title = "Open BizBlox Project File"
        '
        'FSBBX
        '
        Me.FSBBX.DefaultExt = "BBX"
        Me.FSBBX.Filter = "BizBlox Project | *.BBX"
        Me.FSBBX.RestoreDirectory = True
        Me.FSBBX.Title = "Save BizBlox Project File"
        '
        'FOSourceScript
        '
        Me.FOSourceScript.DefaultExt = "txt"
        Me.FOSourceScript.Filter = "Text Files | *.txt"
        Me.FOSourceScript.RestoreDirectory = True
        Me.FOSourceScript.Title = "Select the Property Script to import"
        '
        'txOut
        '
        Me.txOut.BackColor = System.Drawing.Color.White
        Me.txOut.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txOut.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txOut.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.txOut.Font = New System.Drawing.Font("Courier New", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txOut.Location = New System.Drawing.Point(0, 256)
        Me.txOut.MaxLength = 65535
        Me.txOut.Multiline = True
        Me.txOut.Name = "txOut"
        Me.txOut.ReadOnly = True
        Me.txOut.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.txOut.Size = New System.Drawing.Size(528, 230)
        Me.txOut.TabIndex = 3
        Me.txOut.WordWrap = False
        '
        'btStep1A
        '
        Me.btStep1A.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btStep1A.Location = New System.Drawing.Point(11, 24)
        Me.btStep1A.Name = "btStep1A"
        Me.btStep1A.Size = New System.Drawing.Size(152, 23)
        Me.btStep1A.TabIndex = 6
        Me.btStep1A.Text = "Step 1 : Select SQL File"
        '
        'btStep2
        '
        Me.btStep2.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btStep2.Location = New System.Drawing.Point(192, 48)
        Me.btStep2.Name = "btStep2"
        Me.btStep2.Size = New System.Drawing.Size(152, 23)
        Me.btStep2.TabIndex = 6
        Me.btStep2.Text = "Step 2 : Select Target Path"
        '
        'btStep3
        '
        Me.btStep3.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btStep3.Location = New System.Drawing.Point(371, 48)
        Me.btStep3.Name = "btStep3"
        Me.btStep3.Size = New System.Drawing.Size(152, 23)
        Me.btStep3.TabIndex = 6
        Me.btStep3.Text = "Step 3 : Perform Import"
        '
        'cbDataObjects
        '
        Me.cbDataObjects.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cbDataObjects.Location = New System.Drawing.Point(8, 14)
        Me.cbDataObjects.Name = "cbDataObjects"
        Me.cbDataObjects.Size = New System.Drawing.Size(144, 24)
        Me.cbDataObjects.TabIndex = 7
        Me.cbDataObjects.Text = "Render Data Objects"
        '
        'btStep1B
        '
        Me.btStep1B.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btStep1B.Location = New System.Drawing.Point(11, 72)
        Me.btStep1B.Name = "btStep1B"
        Me.btStep1B.Size = New System.Drawing.Size(152, 23)
        Me.btStep1B.TabIndex = 6
        Me.btStep1B.Text = "Step 1 : Select Script File"
        '
        'cbDOCollections
        '
        Me.cbDOCollections.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cbDOCollections.Location = New System.Drawing.Point(8, 38)
        Me.cbDOCollections.Name = "cbDOCollections"
        Me.cbDOCollections.Size = New System.Drawing.Size(136, 24)
        Me.cbDOCollections.TabIndex = 7
        Me.cbDOCollections.Text = "Render DOCollections"
        '
        'cbTransferObjects
        '
        Me.cbTransferObjects.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cbTransferObjects.Location = New System.Drawing.Point(8, 62)
        Me.cbTransferObjects.Name = "cbTransferObjects"
        Me.cbTransferObjects.Size = New System.Drawing.Size(139, 24)
        Me.cbTransferObjects.TabIndex = 7
        Me.cbTransferObjects.Text = "Render Transfer Objects"
        '
        'GroupBox1
        '
        Me.GroupBox1.BackColor = System.Drawing.SystemColors.Control
        Me.GroupBox1.Controls.Add(Me.cbDataObjects)
        Me.GroupBox1.Controls.Add(Me.cbTransferObjects)
        Me.GroupBox1.Controls.Add(Me.cbDOCollections)
        Me.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.GroupBox1.Location = New System.Drawing.Point(16, 128)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(159, 109)
        Me.GroupBox1.TabIndex = 8
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Code Generation Options"
        '
        'btLangVB
        '
        Me.btLangVB.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btLangVB.Location = New System.Drawing.Point(8, 27)
        Me.btLangVB.Name = "btLangVB"
        Me.btLangVB.Size = New System.Drawing.Size(77, 16)
        Me.btLangVB.TabIndex = 8
        Me.btLangVB.Text = "VB.Net 1.1"
        '
        'btLangCS
        '
        Me.btLangCS.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btLangCS.Location = New System.Drawing.Point(8, 51)
        Me.btLangCS.Name = "btLangCS"
        Me.btLangCS.Size = New System.Drawing.Size(77, 16)
        Me.btLangCS.TabIndex = 8
        Me.btLangCS.Text = "C# 1.1"
        '
        'GroupBox2
        '
        Me.GroupBox2.BackColor = System.Drawing.SystemColors.Control
        Me.GroupBox2.Controls.Add(Me.btLangVb2)
        Me.GroupBox2.Controls.Add(Me.btLangVB)
        Me.GroupBox2.Controls.Add(Me.btLangCS2)
        Me.GroupBox2.Controls.Add(Me.btLangCS)
        Me.GroupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.GroupBox2.Location = New System.Drawing.Point(351, 128)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(169, 109)
        Me.GroupBox2.TabIndex = 9
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Language Options"
        '
        'btLangVb2
        '
        Me.btLangVb2.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btLangVb2.Location = New System.Drawing.Point(83, 27)
        Me.btLangVb2.Name = "btLangVb2"
        Me.btLangVb2.Size = New System.Drawing.Size(80, 16)
        Me.btLangVb2.TabIndex = 8
        Me.btLangVb2.Text = "VB.Net 2.0"
        '
        'btLangCS2
        '
        Me.btLangCS2.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btLangCS2.Location = New System.Drawing.Point(83, 51)
        Me.btLangCS2.Name = "btLangCS2"
        Me.btLangCS2.Size = New System.Drawing.Size(80, 16)
        Me.btLangCS2.TabIndex = 8
        Me.btLangCS2.Text = "C# 2.0"
        '
        'cbDtDateMapping
        '
        Me.cbDtDateMapping.Checked = True
        Me.cbDtDateMapping.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cbDtDateMapping.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cbDtDateMapping.Location = New System.Drawing.Point(6, 14)
        Me.cbDtDateMapping.Name = "cbDtDateMapping"
        Me.cbDtDateMapping.Size = New System.Drawing.Size(152, 24)
        Me.cbDtDateMapping.TabIndex = 7
        Me.cbDtDateMapping.Text = "DT_  Style Date Mapping"
        '
        'cbBoundsChecking
        '
        Me.cbBoundsChecking.Checked = True
        Me.cbBoundsChecking.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cbBoundsChecking.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cbBoundsChecking.Location = New System.Drawing.Point(6, 35)
        Me.cbBoundsChecking.Name = "cbBoundsChecking"
        Me.cbBoundsChecking.Size = New System.Drawing.Size(152, 24)
        Me.cbBoundsChecking.TabIndex = 7
        Me.cbBoundsChecking.Text = "Runtime Bounds Checking"
        '
        'GroupBox3
        '
        Me.GroupBox3.BackColor = System.Drawing.SystemColors.Control
        Me.GroupBox3.Controls.Add(Me.cbAddOrderAttributeToDataContractInfo)
        Me.GroupBox3.Controls.Add(Me.cbAddTODataContractInfo)
        Me.GroupBox3.Controls.Add(Me.cbBoundsChecking)
        Me.GroupBox3.Controls.Add(Me.cbDtDateMapping)
        Me.GroupBox3.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.GroupBox3.Location = New System.Drawing.Point(181, 128)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(164, 109)
        Me.GroupBox3.TabIndex = 10
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Options"
        '
        'cbAddTODataContractInfo
        '
        Me.cbAddTODataContractInfo.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cbAddTODataContractInfo.Location = New System.Drawing.Point(6, 57)
        Me.cbAddTODataContractInfo.Name = "cbAddTODataContractInfo"
        Me.cbAddTODataContractInfo.Size = New System.Drawing.Size(152, 24)
        Me.cbAddTODataContractInfo.TabIndex = 7
        Me.cbAddTODataContractInfo.Text = "Add TO DataContract Info"
        '
        'cbAddOrderAttributeToDataContractInfo
        '
        Me.cbAddOrderAttributeToDataContractInfo.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cbAddOrderAttributeToDataContractInfo.Location = New System.Drawing.Point(6, 79)
        Me.cbAddOrderAttributeToDataContractInfo.Name = "cbAddOrderAttributeToDataContractInfo"
        Me.cbAddOrderAttributeToDataContractInfo.Size = New System.Drawing.Size(152, 24)
        Me.cbAddOrderAttributeToDataContractInfo.TabIndex = 8
        Me.cbAddOrderAttributeToDataContractInfo.Text = "Add Order Attribute"
        '
        'Main
        '
        Me.AllowDrop = True
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(528, 502)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.btStep1A)
        Me.Controls.Add(Me.txOut)
        Me.Controls.Add(Me.pgProgress)
        Me.Controls.Add(Me.btStep2)
        Me.Controls.Add(Me.btStep3)
        Me.Controls.Add(Me.btStep1B)
        Me.DoubleBuffered = True
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MaximumSize = New System.Drawing.Size(544, 540)
        Me.Menu = Me.MainMenu1
        Me.MinimumSize = New System.Drawing.Size(544, 540)
        Me.Name = "Main"
        Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "BizBlox Builder"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements IMessageFilter.PreFilterMessage
        If m.Msg = WM_DROPFILES Then
            Dim nfiles As Integer = DragQueryFile(m.WParam, -1, Nothing, 0)
            Dim i As Integer
            For i = 0 To nfiles
                Dim sb As StringBuilder = New StringBuilder(256)
                DragQueryFile(m.WParam, i, sb, 256)
                HandleDroppedFiles(sb.ToString())
            Next
            DragFinish(m.WParam)
            Return True
        End If
        Return False
    End Function

    Public Sub HandleDroppedFiles(ByVal filename As String)
        If Len(filename) > 0 Then
            Try
                Me.detail("Open File: " & filename & vbCrLf)
                Me.DoLoad(filename)
            Catch ex As Exception
                Me.detail(ex.ToString())
            End Try
        End If
    End Sub

    Private Sub SelectSQLSource()
        If Me.FOSourceFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.Project.CurrentProject = BBXProject.ProjectType.SQL
            Me.Project.Source = Me.FOSourceFile.FileName
            Me.detail("Source SQL Script File:" & vbCrLf & Me.FOSourceFile.FileName & vbCrLf)
        End If
    End Sub

    Private Sub SelectOutputTarget()
        If Me.FBOutputPath.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.Project.Destination = Me.FBOutputPath.SelectedPath
            Me.detail("Destination path:" & vbCrLf & Me.FBOutputPath.SelectedPath & vbCrLf)
        End If
    End Sub

    Private Sub SelectScriptSource()
        If Me.FOSourceScript.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.Project.Source = Me.FOSourceScript.FileName
            Me.Project.CurrentProject = BBXProject.ProjectType.SCRIPT
            Me.detail("Source Transfer Object Script File:" & vbCrLf & Me.FOSourceScript.FileName & vbCrLf)
        End If
    End Sub

    Private Sub PerformRender()
        Me.txOut.Clear()
        Try
            Me.Project.performRender(AddressOf callback, AddressOf detail)
        Catch ex As Exception
            MsgBox("Error occurred performing the code generation." & vbCrLf & ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "BizBlox")
            Me.detail("Error occurred performing the code generation." & vbCrLf & ex.Message & vbCrLf)
            callback(0, 100)
            Return
        End Try
        callback(0, 100)
        completed()
    End Sub

    Public Sub callback(ByVal i As Integer, ByVal max As Integer)
        Me.pgProgress.Maximum = max + 1
        Me.pgProgress.Minimum = 0
        Me.pgProgress.Value = IIf(i > max, max, i)
        Me.pgProgress.Update()
    End Sub

    Public Sub detail(ByVal msg As String)
        Me.txOut.AppendText(msg & vbCrLf)
        Me.txOut.ScrollToCaret()
        Me.txOut.Update()
    End Sub

    Public Sub completed()
        detail("Completed " & Now.ToString("f") & vbCrLf & vbCrLf)
    End Sub

    Public Sub DumpProject()
        Me.detail("--------------------------------------------")
        Me.detail("Source File:" & vbCrLf & Me.Project.Source & vbCrLf)
        Me.detail("Destination Path:" & vbCrLf & Me.Project.Destination & vbCrLf)
        Me.detail("Script Type: " & Me.Project.CurrentProject.ToString())
        Me.detail("Output Language: " & Me.Project.OutputLanguage.ToString())
        Me.detail("Output Data Transfer Objects: " & Me.cbTransferObjects.Checked.ToString())
        Me.detail("Output Data Object Collections : " & Me.cbDOCollections.Checked.ToString())
        Me.detail("Output Data Objects: " & Me.cbDataObjects.Checked.ToString())
        Me.detail("Enable DT_ Style Date Mapping: " & Me.cbDtDateMapping.Checked.ToString())
        Me.detail("Enable Runtime Bounds Checking: " & Me.cbBoundsChecking.Checked.ToString())
        Me.detail("--------------------------------------------")
    End Sub

    Private Sub FileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileExit.Click
        Me.Close()
    End Sub

    Private Sub HelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpAbout.Click
        Dim a As New About
        a.ShowDialog()
    End Sub

    Private Sub FileSQLFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileSQLFileOpen.Click
        Me.SelectSQLSource()
    End Sub

    Private Sub FileOutputPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileOutputPath.Click
        Me.SelectOutputTarget()
    End Sub

    Private Sub FilePerformImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FilePerformImport.Click
        Me.PerformRender()
    End Sub

    Private Sub FileOpenClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileProjectFileOpen.Click
        Me.txOut.Clear()
        Dim dr As DialogResult = FOBBX.ShowDialog()
        If dr = Windows.Forms.DialogResult.OK Then
            Me.DoLoad(FOBBX.FileName)
        End If
    End Sub

    Private Sub DoLoad(ByVal filename As String)
        Try
            Me.Project.Load(filename)
            Me.DoLoadImpl()
        Catch ex As Exception
            MsgBox("Error occurred opening the project file:" & vbCrLf & ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "BizBlox")
            Me.detail("Error occurred opening the project file:" & vbCrLf & ex.Message & vbCrLf)
            Return
        End Try
    End Sub

    Private Sub DoLoadImpl()
        Me.detail("Load BBX Project:" & vbCrLf & FOBBX.FileName & vbCrLf)
        If Not Project.ErrorState = BBXProject.errState.OK Then
            MsgBox("Error occurred opening the project file:" & vbCrLf & Me.Project.ErrorMessage, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "BizBlox")
            Me.detail("Error occurred opening the project file:" & vbCrLf & Me.Project.ErrorMessage & vbCrLf)
            Return
        End If
        Me.FOSourceFile.FileName = Me.Project.Source
        Me.FBOutputPath.SelectedPath = Me.Project.Destination
        Me.cbDataObjects.Checked = Me.Project.OutputDataObject
        Me.cbDOCollections.Checked = Me.Project.OutputDOCollection
        Me.cbTransferObjects.Checked = Me.Project.OutputDOTO
        Me.cbBoundsChecking.Checked = Me.Project.EnableRuntimeBoundsCheck
        Me.cbAddTODataContractInfo.Checked = Me.Project.EnableTODataContractInfo
        Me.cbAddOrderAttributeToDataContractInfo.Checked = Me.Project.AddOrderAttributeToDataContractInfo
        Me.cbDtDateMapping.Checked = Me.Project.EnableDTStyleDateMapping
        Me.btLangCS.Checked = False
        Me.btLangVB.Checked = False
        Me.btLangVb2.Checked = False
        Me.btLangCS2.Checked = False
        If Me.Project.OutputLanguage = BBXProject.ProjectLang.CSNET11 Then Me.btLangCS.Checked = True
        If Me.Project.OutputLanguage = BBXProject.ProjectLang.VBNET11 Then Me.btLangVB.Checked = True
        If Me.Project.OutputLanguage = BBXProject.ProjectLang.VBNET20 Then Me.btLangVb2.Checked = True
        If Me.Project.OutputLanguage = BBXProject.ProjectLang.CSNET20 Then Me.btLangCS2.Checked = True
        Me.DumpProject()
    End Sub


    Private Sub FileSaveClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click
        Me.DoSave(Me.Project.Filename())
    End Sub

    Private Sub FileSaveAsClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveAs.Click
        Dim dr As DialogResult = FSBBX.ShowDialog()
        If dr = Windows.Forms.DialogResult.OK Then
            Me.DoSave(FSBBX.FileName)
        End If
    End Sub

    Private Sub DoSave(ByVal filename As String)
        Dim fs As FileStream = File.OpenWrite(filename)
        Me.Project.Save(fs)
        Me.detail("Save BBX Project:" & vbCrLf & filename & vbCrLf)
        If Not Project.ErrorState = BBXProject.errState.OK Then
            MsgBox("Error occurred saving the project file:" & vbCrLf & Me.Project.ErrorMessage, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "BizBlox")
            Me.detail("Error occurred saving the project file:" & vbCrLf & Me.Project.ErrorMessage & vbCrLf)
        End If
        Me.completed()
    End Sub

    Private Sub HelpHelpOutput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpHelpOutput.Click
        Me.txOut.Clear()
        Try
            Dim fileName As String = Application.StartupPath & "\BizBloxBuilder.chm"
            Dim p As Process = Process.Start(fileName)
        Catch ex As Exception
            Me.txOut.AppendText(ex.Message)
        End Try
        Me.completed()
    End Sub

    Private Sub btStep1A_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btStep1A.Click
        Me.SelectSQLSource()
    End Sub

    Private Sub btStep2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btStep2.Click
        Me.SelectOutputTarget()
    End Sub

    Private Sub btStep3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btStep3.Click
        Me.PerformRender()
    End Sub

    Private Sub btStep1B_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btStep1B.Click
        Me.SelectScriptSource()
    End Sub

    Private Sub cbTransferObjects_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbTransferObjects.Click
        Me.Project.OutputDOTO = Me.cbTransferObjects.Checked
        Me.detail("Output Data Transfer Objects: " & Me.cbTransferObjects.Checked.ToString() & vbCrLf)
    End Sub

    Private Sub cbDOCollections_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDOCollections.Click
        Me.Project.OutputDOCollection = Me.cbDOCollections.Checked
        Me.detail("Output Data Object Collections : " & Me.cbDOCollections.Checked.ToString() & vbCrLf)
    End Sub

    Private Sub cbDataObjects_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDataObjects.Click
        Me.Project.OutputDataObject = Me.cbDataObjects.Checked
        Me.detail("Output Data Objects: " & Me.cbDataObjects.Checked.ToString() & vbCrLf)
    End Sub

    Private Sub ToolsProjectInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolsProjectInfo.Click
        Me.DumpProject()
    End Sub

    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
        Dim eFrm As New CryptConnBuilder
        If eFrm.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.detail("Created encrypted connection string.")
            Me.completed()
        End If
    End Sub

    Private Sub btLangVB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLangVB.CheckedChanged
        If Me.btLangVB.Checked Then
            Me.btLangCS.Checked = False
            Me.btLangCS2.Checked = False
            Me.btLangVb2.Checked = False
            Me.Project.OutputLanguage = BBXProject.ProjectLang.VBNET11
        End If
    End Sub

    Private Sub btLangCS_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLangCS.CheckedChanged
        If Me.btLangCS.Checked Then
            Me.btLangVB.Checked = False
            Me.btLangCS2.Checked = False
            Me.btLangVb2.Checked = False
            Me.Project.OutputLanguage = BBXProject.ProjectLang.CSNET11
        End If
    End Sub

    Private Sub btLangVB2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLangVb2.CheckedChanged
        If Me.btLangVb2.Checked Then
            Me.btLangCS.Checked = False
            Me.btLangCS2.Checked = False
            Me.btLangVB.Checked = False
            Me.Project.OutputLanguage = BBXProject.ProjectLang.VBNET20
        End If
    End Sub

    Private Sub btLangCS2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLangCS2.CheckedChanged
        If Me.btLangCS2.Checked Then
            Me.btLangCS.Checked = False
            Me.btLangVB.Checked = False
            Me.btLangVb2.Checked = False
            Me.Project.OutputLanguage = BBXProject.ProjectLang.CSNET20
        End If
    End Sub

    Private Sub SetTitle()
        Me.Text = "BizBlox Builder " & Application.ProductVersion
    End Sub

    Private Sub DoLog(ByVal text As String)
        MessageBox.Show(text)
    End Sub

    Private Sub DoLog(ByVal text As String, ByVal ex As Exception)
        MessageBox.Show(text & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
    End Sub

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub


    Private Sub cbDtDateMapping_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDtDateMapping.Click
        Me.Project.EnableDTStyleDateMapping = Me.cbDtDateMapping.Checked
        Me.detail("Enable DT_ Style Date Mapping: " & Me.cbDtDateMapping.Checked.ToString() & vbCrLf)
    End Sub

    Private Sub cbBoundsChecking_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbBoundsChecking.Click
        Me.Project.EnableRuntimeBoundsCheck = Me.cbBoundsChecking.Checked
        Me.detail("Enable Runtime Bounds Checking: " & Me.cbBoundsChecking.Checked.ToString() & vbCrLf)
    End Sub

    Private Sub cbAddTODataContractInfo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbAddTODataContractInfo.Click
        Me.Project.EnableTODataContractInfo = Me.cbAddTODataContractInfo.Checked
        Me.detail("Enable TO Data Contract Info: " & Me.cbAddTODataContractInfo.Checked.ToString() & vbCrLf)
    End Sub

    Private Sub cbAddOrderAttributeToDataContractInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbAddOrderAttributeToDataContractInfo.Click
        Me.Project.AddOrderAttributeToDataContractInfo = Me.cbAddOrderAttributeToDataContractInfo.Checked
        Me.detail("Enable Add Order Attribute To Data Contract Info: " & Me.cbAddOrderAttributeToDataContractInfo.Checked.ToString() & vbCrLf)
    End Sub

    Delegate Sub InvokeWrapper()
    Private InvokeHandle As InvokeWrapper

    Private Sub ProjectChangedImplementation()
        Me.DoLoadImpl()
    End Sub

    Private Sub ReImportImplementation()
        If Me.ToolsWatchSource.Checked Then
            Me.DoLoadImpl()
            Me.PerformRender()
        End If
    End Sub

    ''' <summary>
    ''' Added handler for changed project to reload.         
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Project_ProjectChanged() Handles Project.ProjectChanged
        Me.InvokeHandle = AddressOf ProjectChangedImplementation
        Me.Invoke(Me.InvokeHandle)
    End Sub

    ''' <summary>
    ''' Added handler for changed project to reload
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Project_ReImport() Handles Project.ReImport
        Me.InvokeHandle = AddressOf ReImportImplementation
        Me.Invoke(Me.InvokeHandle)
    End Sub

    Private Sub ToolsWatchSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolsWatchSource.Click
        Me.ToolsWatchSource.Checked = IIf(Me.ToolsWatchSource.Checked, False, True)
    End Sub

End Class